home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / cdedit / preview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  7.9 KB  |  268 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/cdEdit/RCS/preview.c,v 2.1 92/07/17 16:35:04 drapeau Exp $ */
  25. /* $Log:    preview.c,v $
  26.  * Revision 2.1  92/07/17  16:35:04  drapeau
  27.  * Minor changes to PreviewStart(), PreviewEnd(), to make
  28.  * overflow code more robust (can now handle overflows of greater than
  29.  * one second).
  30.  * 
  31.  * Revision 2.0  91/10/06  21:01:52  chua
  32.  * Update to version 2.0
  33.  * 
  34.  * Revision 1.11  91/09/03  15:23:24  chua
  35.  * Added the copyright header.
  36.  * 
  37.  * The preview button has now been changed to a menu button, with 2 entries: Play whole
  38.  * edit, and Play part of edit.  The handlers for these two items are in this file.
  39.  * 
  40.  * Play part of edit will open the preview popup window, which allows playing the first or
  41.  * last few seconds of an edit (as previously).  
  42.  * 
  43.  * Revision 1.1  91/07/09  16:48:02  chua
  44.  * 
  45.  * 
  46.  * Revision 1.0  91/07/08  13:46:30  chua
  47.  * Initial revision
  48.  *  */
  49.  
  50. static char previewrcsid[] = "$Header: /Source/Media/collab/cdEdit/RCS/preview.c,v 2.1 92/07/17 16:35:04 drapeau Exp $";
  51.  
  52. #include "main.h"
  53.  
  54. /*
  55.  * Menu handler for `PreviewMenu (Play whole edit)'.
  56.  * Calls PreviewStartEnd to play the whole edit.
  57.  */
  58. Menu_item PlayWholeEditHandler(item, op)
  59.      Menu_item    item;
  60.      Menu_generate    op;
  61. {
  62.   switch (op) 
  63.   {
  64.    case MENU_DISPLAY:
  65.     break;
  66.    case MENU_DISPLAY_DONE:
  67.     break;
  68.    case MENU_NOTIFY:
  69.     if (SetDuration(-1) != Error)                    /* Display the duration of the current selection */
  70.     {
  71.       PreviewStartEnd(item, NULL);
  72.     }
  73.     break;
  74.    case MENU_NOTIFY_DONE:
  75.     break;
  76.   }
  77.   return item;
  78. }
  79.  
  80. /*
  81.  * Menu handler for `PreviewMenu (Play part of edit ...)'.
  82.  * Opens the preview popup window so that the user can choose to play either the first or last parts of an edit.
  83.  */
  84. Menu_item PlayPartialEditHandler(item, op)
  85.      Menu_item    item;
  86.      Menu_generate    op;
  87. {
  88.   switch (op) 
  89.   {
  90.    case MENU_DISPLAY:
  91.     break;
  92.    case MENU_DISPLAY_DONE:
  93.     break;
  94.    case MENU_NOTIFY:
  95.     SetDuration(-1);                            /* Display the duration of the current selection */
  96.     xv_set(cdEdit_PreviewPopup->PreviewPopup, FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  97.     xv_set(cdEdit_PreviewPopup->PreviewPopup, XV_SHOW, TRUE, NULL);
  98.     break;
  99.    case MENU_NOTIFY_DONE:
  100.     break;
  101.   }
  102.   return item;
  103. }
  104.  
  105. /*
  106.  * Notify callback function for `PreviewStartEndButton'.
  107.  * Preview the current selection from start to end.
  108.  * This function is also called by the PerformSelection procedure as the selection to be performed would have been loaded into the current selection
  109.  * textfields by the time this function is called.
  110.  */
  111. void PreviewStartEnd(item, event)
  112.      Panel_item    item;
  113.      Event        *event;
  114. {
  115.   Msf absoluteStart, absoluteEnd;
  116.   struct cdrom_msf msf;
  117.   
  118.   if (offset == 1) 
  119.   {
  120.     absoluteStart = offsetStart;                    /* There is an offset.  Play from the offset start time instead */
  121.     offset = 0;
  122.   }
  123.   else 
  124.   {
  125.     absoluteStart = (Msf) GetCurrentStart();                /* Get the start time */
  126.   }
  127.   absoluteEnd = NULL;
  128.   if (absoluteStart == NULL) 
  129.   {
  130.     return;
  131.   }
  132.   absoluteEnd = (Msf) GetCurrentEnd();                    /* Get the end time */
  133.   if (absoluteEnd == NULL) 
  134.   {
  135.     return;
  136.   }
  137.   if (CheckSelection(absoluteStart, absoluteEnd) == Error)        /* Check that the selection is valid */
  138.   {
  139.     return;
  140.   }
  141.   msf.cdmsf_min0 = absoluteStart->min;                    /* Set the time limits to play from/to. */
  142.   msf.cdmsf_sec0 = absoluteStart->sec;
  143.   msf.cdmsf_frame0 = absoluteStart->frame;
  144.   msf.cdmsf_min1 = absoluteEnd->min;
  145.   msf.cdmsf_sec1 = absoluteEnd->sec;
  146.   msf.cdmsf_frame1 = absoluteEnd->frame;
  147.   playerState = PlayMode;
  148.   cdrom_play_msf(fd, msf);
  149. }
  150.  
  151. /*
  152.  * Notify callback function for `PreviewStartButton'.
  153.  * Preview the first x seconds of the current selection.
  154.  */
  155. void PreviewStart(item, event)
  156.      Panel_item    item;
  157.      Event        *event;
  158. {
  159.   Msf absoluteStart, absoluteEnd, endMsf;
  160.   struct cdrom_msf msf;
  161.   int duration;
  162.   
  163.   absoluteStart = (Msf) GetCurrentStart();                /* Get the start time */
  164.   absoluteEnd = NULL;
  165.   if (absoluteStart == NULL)    
  166.   {
  167.     return;
  168.   }
  169.   absoluteEnd = (Msf) GetCurrentEnd();                    /* Get the end time */
  170.   if (absoluteEnd == NULL) 
  171.   {
  172.     return;
  173.   }
  174.   if (CheckSelection(absoluteStart, absoluteEnd) == Error)        /* Check that the times are valid */
  175.   {
  176.     return;
  177.   }
  178.   duration = xv_get(cdEdit_PreviewPopup->PreviewTimeText, PANEL_VALUE);    /* Get the duration that the preview is to be played */
  179.   endMsf = (Msf) malloc(sizeof(struct msf));                /* Set the end time based on the duration */
  180.   endMsf->min = absoluteStart->min; 
  181.   endMsf->sec = absoluteStart->sec + duration;
  182.   endMsf->frame = absoluteStart->frame;
  183.   while (endMsf->sec >= 60) 
  184.   {
  185.     endMsf->sec -= 60;
  186.     endMsf->min++;
  187.   }
  188.   if (CompareMsf(endMsf, absoluteEnd) == Greater) 
  189.   {
  190.     endMsf = absoluteEnd;
  191.   }
  192.   msf.cdmsf_min0 = absoluteStart->min;                    /* Set the time limits to play from/to */
  193.   msf.cdmsf_sec0 = absoluteStart->sec;
  194.   msf.cdmsf_frame0 = absoluteStart->frame;
  195.   msf.cdmsf_min1 = endMsf->min;
  196.   msf.cdmsf_sec1 = endMsf->sec;
  197.   msf.cdmsf_frame1 = endMsf->frame;
  198.   playerState = PlayMode;
  199.   cdrom_play_msf(fd, msf);
  200.   free (endMsf);
  201. }
  202.  
  203. /*
  204.  * Notify callback function for `PreviewEndButton'.
  205.  * Preview the last x seconds of the current selection.
  206.  */
  207. void PreviewEnd(item, event)
  208.      Panel_item    item;
  209.      Event        *event;
  210. {
  211.   Msf absoluteStart, absoluteEnd, startMsf;
  212.   struct cdrom_msf msf;
  213.   int duration;
  214.   
  215.   absoluteStart = (Msf) GetCurrentStart();                /* Get the start time */
  216.   absoluteEnd = NULL;
  217.   if (absoluteStart == NULL)    
  218.   {
  219.     return;
  220.   }
  221.   absoluteEnd = (Msf) GetCurrentEnd();                    /* Get the end time */
  222.   if (absoluteEnd == NULL) 
  223.   {
  224.     return;
  225.   }
  226.   if (CheckSelection(absoluteStart, absoluteEnd) == Error)        /* Check that the time is valid */
  227.   {
  228.     return;
  229.   }
  230.   duration = xv_get(cdEdit_PreviewPopup->PreviewTimeText,        /* Get the duration that the preview is to be played */
  231.             PANEL_VALUE);
  232.   startMsf = (Msf) malloc(sizeof(struct msf));                /* Set the start time based on the duration */
  233.   startMsf->min = absoluteEnd->min;
  234.   startMsf->sec = absoluteEnd->sec - duration;
  235.   startMsf->frame = absoluteEnd->frame;
  236.   while (startMsf->sec < 0)
  237.   {
  238.     startMsf->sec +=60;
  239.     startMsf->min--;
  240.   }
  241.   if (CompareMsf(startMsf, absoluteStart) == Less) 
  242.   {
  243.     startMsf = absoluteStart;
  244.   }
  245.   msf.cdmsf_min0 = startMsf->min;                    /* Set the time limits to play from/to */
  246.   msf.cdmsf_sec0 = startMsf->sec;
  247.   msf.cdmsf_frame0 = startMsf->frame;
  248.   msf.cdmsf_min1 = absoluteEnd->min;
  249.   msf.cdmsf_sec1 = absoluteEnd->sec;
  250.   msf.cdmsf_frame1 = absoluteEnd->frame;
  251.   playerState = PlayMode;
  252.   cdrom_play_msf(fd, msf);
  253.   free (startMsf);
  254.   
  255. }
  256.  
  257. /*
  258.  * Notify callback function for `ClosePreviewPopupButton'.
  259.  * Close the preview popup window.
  260.  */
  261. void PreviewDone(item, event)
  262.      Panel_item    item;
  263.      Event        *event;
  264. {
  265.   xv_set(cdEdit_PreviewPopup->PreviewPopup, FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  266.   xv_set(cdEdit_PreviewPopup->PreviewPopup, XV_SHOW, FALSE, NULL);
  267. }
  268.